package com.heima.feigns.fallback;

import com.heima.feigns.AdminFeign;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class AdminFeignFallback implements FallbackFactory<AdminFeign> {

    @Override
    public AdminFeign create(Throwable throwable) {
        throwable.printStackTrace();
        //降级方法
        return new AdminFeign() {

            @Override
            public ResponseResult<List<String>> findAllSensitive() {

                log.error("AdminFeign sensitives 远程调用出错啦 ~~~ !!!! {} ",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
            }

            @Override
            public ResponseResult findOne(Integer id) {
                log.error("AdminFeign findOne 远程调用出错啦 ~~~ !!!! {} ",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);

            }

            @Override
            public ResponseResult<List<AdChannel>> selectChannels() {
                log.error("AdminFeign selectChannels 远程调用出错啦 ~~~ !!!! {} ",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
            }

        };
    }
}
//    @Override
//    public AdminFeign create(Throwable throwable) {
//        throwable.printStackTrace();
//        //降级方法
//        return new AdminFeign() {
//
//            @Override
//            public ResponseResult<List<String>> findAllSensitive() {
//
//                log.error("AdminFeign sensitives 远程调用出错啦 ~~~ !!!! {} ",throwable.getMessage());
//                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
//            }
//
//        };
//    }